﻿Imports DevExpress.XtraEditors
Imports DevExpress.XtraSplashScreen

Public Class IClass
    Public Event TheEvent()
    Public Sub Work()
        RaiseEvent TheEvent()
    End Sub
    Private lst, lstGuidDeleted, lstGuidDeleted_tab1, lstGuidDeleted_tab2, lstGuidDeleted_tab3, lstGuidDeleted_tab4, lstGuidDeleted_tab5, lstGuidDeleted_tab6 As ArrayList
    Private ds As DataSet
    Private ad, ad1, ad2, ad3, ad4, ad5, ad6, ad7, ad8, ad9, ad10 As Object
    Private dt, dt1, dt2, dt3, dt4, dt5, dt6, dt7, dt8, dt9, dt10 As DataTable
    Private bd, bd1, bd2, bd3, bd4, bd5, bd6, bd7, bd8, bd9, bd10 As BindingSource
    Private igridview, igridview1, igridview2, igridview3, igridview4, igridview5, _
        igridview6, igridview7, igridview8, igridview9, igridview10 As IGridView
    Private am As Object 'adaptermanager
    Private controlFocus As BaseEdit
    Public Sub New()
        lst = New ArrayList
        lstGuidDeleted = New ArrayList
        lstGuidDeleted_tab1 = New ArrayList
        lstGuidDeleted_tab2 = New ArrayList
        lstGuidDeleted_tab3 = New ArrayList
        lstGuidDeleted_tab4 = New ArrayList
        lstGuidDeleted_tab5 = New ArrayList
        lstGuidDeleted_tab6 = New ArrayList
    End Sub
    'truong hop form don
    Public Sub New(ds As DataSet, dt As DataTable, am As Object, ad As Object, bd As BindingSource, ByVal igridview As IGridView, ByVal control As Control)
        Me.ds = ds
        Me.dt = dt
        Me.am = am
        Me.bd = bd
        Me.ad = ad
        Me.igridview = igridview
        Me.controlFocus = control
    End Sub
    'truong hop form doi
    Public Sub addTab1(ByVal dt1 As DataTable, ByVal bd1 As BindingSource, ByVal ad1 As Object, ByVal igridview1 As IGridView)
        Me.dt1 = dt1
        Me.bd1 = bd1
        Me.ad1 = ad1
        Me.igridview1 = igridview1
    End Sub
    Public Sub addTab2(ByVal dt2 As DataTable, ByVal bd2 As BindingSource, ByVal ad2 As Object, ByVal igridview2 As IGridView)
        Me.dt2 = dt2
        Me.bd2 = bd2
        Me.ad2 = ad2
        Me.igridview2 = igridview2
    End Sub
    Public Sub addTab3(ByVal dt3 As DataTable, ByVal bd3 As BindingSource, ByVal ad3 As Object, ByVal igridview3 As IGridView)
        Me.dt3 = dt3
        Me.bd3 = bd3
        Me.ad3 = ad3
        Me.igridview3 = igridview3
    End Sub
    Public Sub addTab4(ByVal dt4 As DataTable, ByVal bd4 As BindingSource, ByVal ad4 As Object, ByVal igridview4 As IGridView)
        Me.dt4 = dt4
        Me.bd4 = bd4
        Me.ad4 = ad4
        Me.igridview4 = igridview4
    End Sub
    Public Sub addTab5(ByVal dt5 As DataTable, ByVal bd5 As BindingSource, ByVal ad5 As Object, ByVal igridview5 As IGridView)
        Me.dt5 = dt5
        Me.bd5 = bd5
        Me.ad5 = ad5
        Me.igridview5 = igridview5
    End Sub
    Public Sub addTab6(ByVal dt6 As DataTable, ByVal bd6 As BindingSource, ByVal ad6 As Object, ByVal igridview6 As IGridView)
        Me.dt6 = dt6
        Me.bd6 = bd6
        Me.ad6 = ad6
        Me.igridview6 = igridview6
    End Sub
    Public Sub addTab7(ByVal dt7 As DataTable, ByVal bd7 As BindingSource, ByVal ad7 As Object, ByVal igridview7 As IGridView)
        Me.dt7 = dt7
        Me.bd7 = bd7
        Me.ad7 = ad7
        Me.igridview7 = igridview7
    End Sub
    Public Sub addTab8(ByVal dt8 As DataTable, ByVal bd8 As BindingSource, ByVal ad8 As Object, ByVal igridview8 As IGridView)
        Me.dt8 = dt8
        Me.bd8 = bd8
        Me.ad8 = ad8
        Me.igridview8 = igridview8
    End Sub
    Public Sub addTab9(ByVal dt9 As DataTable, ByVal bd9 As BindingSource, ByVal ad9 As Object, ByVal igridview9 As IGridView)
        Me.dt9 = dt9
        Me.bd9 = bd9
        Me.ad9 = ad9
        Me.igridview9 = igridview9
    End Sub
    Public Sub addTab10(ByVal dt10 As DataTable, ByVal bd10 As BindingSource, ByVal ad10 As Object, ByVal igridview10 As IGridView)
        Me.dt10 = dt10
        Me.bd10 = bd10
        Me.ad10 = ad10
        Me.igridview10 = igridview10
    End Sub

    Public Function getMoveLast()
        Try
            Me.bd.MoveLast()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            Return False
        End Try
        Return True
    End Function
    Public Function getMoveNext()
        Try
            Me.bd.MoveNext()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            Return False
        End Try
        Return True
    End Function
    Public Function getMovePrevious()
        Try
            Me.bd.MovePrevious()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            Return False
        End Try
        Return True
    End Function
    Public Function getMoveFirst()
        Try
            Me.bd.MoveFirst()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            Return False
        End Try
        Return True
    End Function
    Public Function getRefresh()
        Try
            Me.bd.EndEdit()
            If Me.ds.HasChanges Then
                If DevExpress.XtraEditors.XtraMessageBox.Show("Dữ liệu đã có thay đổi, bạn có muốn hủy những thay đổi và làm tươi lại không ?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Information) = Windows.Forms.DialogResult.Yes Then
                    Me.ds.RejectChanges()
                    Return True
                Else
                    Return False
                End If
            Else
                Dim position As Integer = Me.bd.Position
                Me.bd.Position = position
                If Not IsNothing(ad) Then
                    Me.ad.fill(Me.dt)
                End If
                If Not IsNothing(ad1) Then
                    Me.ad1.fill(Me.dt1)
                End If
                If Not IsNothing(ad2) Then
                    Me.ad2.fill(Me.dt2)
                End If
                If Not IsNothing(ad3) Then
                    Me.ad3.fill(Me.dt3)
                End If
                If Not IsNothing(ad4) Then
                    Me.ad4.fill(Me.dt4)
                End If
                If Not IsNothing(ad5) Then
                    Me.ad5.fill(Me.dt5)
                End If
                If Not IsNothing(ad6) Then
                    Me.ad6.fill(Me.dt6)
                End If
                If Not IsNothing(ad7) Then
                    Me.ad7.fill(Me.dt7)
                End If
                If Not IsNothing(ad8) Then
                    Me.ad8.fill(Me.dt8)
                End If
                If Not IsNothing(ad9) Then
                    Me.ad9.fill(Me.dt9)
                End If
                If Not IsNothing(ad10) Then
                    Me.ad10.fill(Me.dt10)
                End If
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            Return False
            Exit Function
        End Try
        Return True
    End Function
    Public Function getUndo()
        Try
            Me.bd.EndEdit()
            If Me.ds.HasChanges Then
                If DevExpress.XtraEditors.XtraMessageBox.Show("Bạn có muốn hủy tất cả những thay đổi đang xảy ra  không ?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Information) = Windows.Forms.DialogResult.Yes Then
                    Me.ds.RejectChanges()
                Else
                    Return False
                End If
            Else
                DevExpress.XtraEditors.XtraMessageBox.Show("Chưa có thay đổi dữ liệu ?", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information)
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            Return False
        End Try
        Return True
    End Function
    Public Function getDelete()
        Try
            If DevExpress.XtraEditors.XtraMessageBox.Show("Bạn có muốn xóa '" & Me.controlFocus.Text & "' không ?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Error) = Windows.Forms.DialogResult.Yes Then
                Me.bd.EndEdit()
                Me.bd.RemoveCurrent()
                am.updateAll(Me.ds)
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            Return False
        End Try
        Return True
    End Function
    Public Function getNew()
        Try
            Me.bd.AddNew()
            Me.controlFocus.Focus()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            Return False
        End Try
        Return True
    End Function
    Private Sub setLstGuiDeleted()
        If dt IsNot Nothing Then
            Dim myView As New DataView(dt, Nothing, Nothing, DataViewRowState.Deleted)
            Dim myTable As DataTable = myView.ToTable()
            lstGuidDeleted.Clear()
            For Each deletedRow As DataRow In myTable.Rows
                lstGuidDeleted.Add(CType(deletedRow.Item("uid"), System.Guid))
            Next
        End If
        '============== tab1 ======================================
        If dt1 IsNot Nothing Then
            Dim myView1 As New DataView(dt1, Nothing, Nothing, DataViewRowState.Deleted)
            Dim myTable_tab1 As DataTable = myView1.ToTable()
            lstGuidDeleted_tab1.Clear()
            For Each deletedRow As DataRow In myTable_tab1.Rows
                lstGuidDeleted_tab1.Add(CType(deletedRow.Item("uid"), System.Guid))
            Next
        End If
        '============== tab2 ======================================
        If dt2 IsNot Nothing Then
            Dim myView2 As New DataView(dt2, Nothing, Nothing, DataViewRowState.Deleted)
            Dim myTable_tab2 As DataTable = myView2.ToTable()
            lstGuidDeleted_tab2.Clear()
            For Each deletedRow As DataRow In myTable_tab2.Rows
                lstGuidDeleted_tab2.Add(CType(deletedRow.Item("uid"), System.Guid))
            Next
        End If
        '============== tab3 ======================================
        If dt3 IsNot Nothing Then
            Dim myView3 As New DataView(dt3, Nothing, Nothing, DataViewRowState.Deleted)
            Dim myTable_tab3 As DataTable = myView3.ToTable()
            lstGuidDeleted_tab3.Clear()
            For Each deletedRow As DataRow In myTable_tab3.Rows
                lstGuidDeleted_tab3.Add(CType(deletedRow.Item("uid"), System.Guid))
            Next
        End If
        '============== tab4 ======================================
        If dt4 IsNot Nothing Then
            Dim myView4 As New DataView(dt4, Nothing, Nothing, DataViewRowState.Deleted)
            Dim myTable_tab4 As DataTable = myView4.ToTable()
            lstGuidDeleted_tab4.Clear()
            For Each deletedRow As DataRow In myTable_tab4.Rows
                lstGuidDeleted_tab4.Add(CType(deletedRow.Item("uid"), System.Guid))
            Next
        End If
        '============== tab5 ======================================
        If dt5 IsNot Nothing Then
            Dim myView5 As New DataView(dt5, Nothing, Nothing, DataViewRowState.Deleted)
            Dim myTable_tab5 As DataTable = myView5.ToTable()
            lstGuidDeleted_tab5.Clear()
            For Each deletedRow As DataRow In myTable_tab5.Rows
                lstGuidDeleted_tab5.Add(CType(deletedRow.Item("uid"), System.Guid))
            Next
        End If
        '============== tab6 ======================================
        If dt6 IsNot Nothing Then
            Dim myView6 As New DataView(dt6, Nothing, Nothing, DataViewRowState.Deleted)
            Dim myTable_tab6 As DataTable = myView6.ToTable()
            lstGuidDeleted_tab6.Clear()
            For Each deletedRow As DataRow In myTable_tab6.Rows
                lstGuidDeleted_tab6.Add(CType(deletedRow.Item("uid"), System.Guid))
            Next
        End If
    End Sub
    Public Overridable Sub setSubTruoc_UpdateAll()
    End Sub
    Public Function getSave()
        Try
            'Me.igridview.setUpdateData()
            bd.EndEdit()
            If Me.ds.HasChanges Then 'coi có thay đổi dữ liệu hay ko ?
                If DevExpress.XtraEditors.XtraMessageBox.Show("Bạn có muốn 'Lưu' không ?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Information) = Windows.Forms.DialogResult.Yes Then
                    setLstGuiDeleted()
                    setSubTruoc_UpdateAll()
                    am.updateAll(Me.ds)
                Else
                    ds.RejectChanges()
                End If
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            Return False
        End Try
        Return True
    End Function
    ''' <summary>
    ''' Lấy danh sách của những uid bị xóa (cha)
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function getLstUidDelete() As ArrayList
        Return lstGuidDeleted
    End Function
    ''' <summary>
    ''' Lấy danh sách những uid bị xóa (tab1)
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function getLstUidDelete_Tab1() As ArrayList
        Return lstGuidDeleted_tab1
    End Function
    ''' <summary>
    ''' Lấy danh sách những uid bị xóa (tab2)
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function getLstUidDelete_Tab2() As ArrayList
        Return lstGuidDeleted_tab2
    End Function
    ''' <summary>
    ''' Lấy danh sách những uid bị xóa (tab3)
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function getLstUidDelete_Tab3() As ArrayList
        Return lstGuidDeleted_tab3
    End Function
    ''' <summary>
    ''' Lấy danh sách những uid bị xóa (tab4)
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function getLstUidDelete_Tab4() As ArrayList
        Return lstGuidDeleted_tab4
    End Function
    ''' <summary>
    ''' Lấy danh sách những uid bị xóa (tab5)
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function getLstUidDelete_Tab5() As ArrayList
        Return lstGuidDeleted_tab5
    End Function
    ''' <summary>
    ''' Lấy danh sách những uid bị xóa (tab6)
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function getLstUidDelete_Tab6() As ArrayList
        Return lstGuidDeleted_tab6
    End Function
    Public Function getLst()
        Return lst
    End Function
    Public Function getDs()
        Return ds
    End Function
    Public Function getDt()
        Return dt
    End Function
    Public Function getBd()
        Return bd
    End Function
    Public Function getAd()
        Return am
    End Function
    Public Sub setDs(ByVal ds As DataSet)
        Me.ds = ds
    End Sub
    Public Sub setDt(ByVal dt As DataTable)
        Me.dt = dt
    End Sub
    Public Sub setBd(ByVal bd As BindingSource)
        Me.bd = bd
    End Sub
    Public Sub setAd(ByVal am As Object)
        Me.am = am
    End Sub
    Public Sub setObj(ByVal ds As DataSet, ByVal dt As DataTable, ByVal bd As BindingSource, ByVal am As Object, ByVal ad As Object, ByVal igridview As IGridView, ByVal control As BaseEdit)
        Me.ds = ds
        Me.dt = dt
        Me.bd = bd
        Me.am = am
        Me.ad = ad
        Me.igridview = igridview
        Me.controlFocus = control
    End Sub
    Public Sub setObj(ByVal ds As DataSet, ByVal dt As DataTable, ByVal bd As BindingSource, ByVal am As Object, ByVal ad As Object, ByVal control As BaseEdit)
        Me.ds = ds
        Me.dt = dt
        Me.bd = bd
        Me.am = am
        Me.ad = ad
        Me.controlFocus = control
    End Sub
End Class
